package com.yunji.framework_template.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yunji.framework_template.biz.service.UsersService;
import com.yunji.framework_template.common.web.Page;
import com.yunji.framework_template.common.web.Result;
import com.yunji.framework_template.orm.persistence.model.Users;

/**
 * Created by fenglibin on 2018/11/26.
 */
@Controller
@RequestMapping("/users/")
public class UsersController {

    @Autowired
    UsersService usersService;

    @RequestMapping("selectAll")
    @ResponseBody
    public Result<List<Users>> selectAll() {
        return Result.success(usersService.selectAll());
    }

    @RequestMapping("select")
    @ResponseBody
    public Result<Users> selectByPrimaryKey(Integer id) {
        return Result.success(usersService.selectByPrimaryKey(id));
    }

    @RequestMapping("selectByCondition")
    @ResponseBody
    public Result<List<Users>> selectByCondition(Users record) {
        return Result.success(usersService.selectByCondition(record));
    }

    @RequestMapping("count")
    @ResponseBody
    public Result<Integer> count(Users record) {
        return Result.success(usersService.count(record));
    }

    @RequestMapping("insert")
    @ResponseBody
    public Result<Integer> insertSelective(Users record) {
        return Result.success(usersService.insertSelective(record));
    }

    @RequestMapping("update")
    @ResponseBody
    public Result<Integer> updateByPrimaryKeySelective(Users record) {
        return Result.success(usersService.updateByPrimaryKeySelective(record));
    }

    @RequestMapping("selectByPage")
    @ResponseBody
    public Result<Page<List<Users>>> selectByPage(Page<Users> page) {
        List<Users> list = null;
        page = page.sequentialDisplayCalculate(usersService.count(page.getObj()));
        if (page.getTotalCount() > 0) {
            list = usersService.selectByPage(page);
        }
        Page<List<Users>> result = new Page<List<Users>>(page, list);
        return Result.success(result);
    }

    @RequestMapping("deleteByCondition1")
    @ResponseBody
    public Result<Integer> deleteByCondition(Users record) {
        return Result.success(usersService.deleteByCondition(record));
    }

    @RequestMapping("delete1")
    @ResponseBody
    public Result<Integer> deleteByPrimaryKey(Integer id) {
        return Result.success(usersService.deleteByPrimaryKey(id));
    }

}
